package com.abapi.pay.admin.support.db.service.impl;

import com.abapi.pay.admin.data.ClientData;
import com.abapi.pay.admin.data.ClientInfo;
import com.abapi.pay.admin.support.db.service.IndexService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.sun.corba.se.spi.ior.ObjectKey;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

/**
 * @Author ldx
 * @Date 2020/2/1 17:28
 * @Description
 * @Version 1.0.0
 */
@Service
public class IndexServiceInpl implements IndexService {
    @Override
    public Map<String, Object> indexData() {
        Map<String,Object> map = Maps.newHashMap();
        map.put("nowTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        map.put("projectCount",ClientData.clientData.size());
        map.put("adminCount",1);
        List<Map<String,Object>> projects = Lists.newArrayList();
        for (Map.Entry<String, List<ClientInfo>> e: ClientData.clientData.entrySet()) {
            Map<String, Object> projectMap = Maps.newHashMap();
            projectMap.put("projectName",e.getKey());
            StringBuilder projectNodes = new StringBuilder();
            e.getValue().stream().forEach(c->projectNodes.append(c.getIp()+","));
            projectMap.put("projectNodes",projectNodes.toString());
            projects.add(projectMap);
        }
        map.put("projects",projects);
        return map;
    }
}
